package jdk;
import java.util.Arrays;

/**
 * Programer.java created by zhangzhidong 
 * at 下午7:32:13 2016年10月14日
 */
interface inter{
	int a = 2;
}
public class Programer {
	public static void main(String[] args) {
		Programer p = new Programer();
		p.iter(new int []{1,2,3,4,5,6,7},5);
	}
	public void iter(int arr[],int r){
		for(int i =r;i<=arr.length;i++){
			get(arr,i);
		}
		System.out.println(arr[0]);
	}
	public  void get(int a[],int r){
		int b [] = new int [a.length];
		int len = a.length;
		for(int i=0;i<a.length;i++){
			int start = i;
			int end = i+r-1;
			int length = end-start+1;
			int temp[] = new int[length];
			int index =0;
			for(int k=start;k<=end;k++){
					temp[index++]= a[k % len];
			}
			b[i] = getmedian(temp);
		}
		System.arraycopy(b, 0, a, 0, b.length);
	}
	public static int getmedian(int arr[]){
		Arrays.sort(arr);
		int num = arr.length;
		int mid = arr.length>>1;
		if(num %2 ==0){
			int pre = mid-1;
			return arr[pre]>arr[mid]?arr[pre]:arr[mid];
		}else{
			return arr[mid];
		}
	}
}